/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import org.ukui.qqc2style.private 1.0 as StylePrivate

Popup {
    id: uninstallDialog
    property string desktopFile
    property string infoBoxText
    property string infoBoxImageSource

    width:  520
    height: 220
    background: Rectangle {
        color: "transparent"
    }
    anchors.centerIn: parent
    modal: true
    closePolicy: Popup.NoAutoClose
    contentItem: Rectangle {
        color: StylePrivate.StyleHelper.windowcolorrole
        visible: true; radius: Style.tabletScaleFactor * 22
        width:  520; height: 220
        anchors.horizontalCenter: parent.horizontalCenter; anchors.verticalCenter: parent.verticalCenter
        ColumnLayout {
            spacing: 0
            anchors.fill: parent; Layout.alignment: Qt.AlignCenter
            Layout.fillHeight: true; Layout.fillWidth: true
            RowLayout {
                width: Style.tabletScaleFactor * 400; height: Style.tabletScaleFactor * 64
                spacing: Style.tabletScaleFactor * 16; Layout.leftMargin: Style.tabletScaleFactor * 40
                Layout.topMargin: Style.tabletScaleFactor * 20
                Image {
                    id: infoBoxImage
                    Layout.maximumHeight: Style.tabletScaleFactor *64
                    Layout.maximumWidth: Style.tabletScaleFactor *64
                    sourceSize: Qt.size(Style.tabletScaleFactor *64, Style.tabletScaleFactor *64)
                    source: "image://icons/" + infoBoxImageSource
                }
                Text {
                    text: String(qsTr("Remove \"%1\"?")).arg(infoBoxText)// qsTr("Remove ") + qsTr("\"") + infoBoxText + qsTr("\"") + qsTr("?")
                    width: Style.tabletScaleFactor * 154; height: Style.tabletScaleFactor * 25
                    font.pointSize: 13
                    color: StylePrivate.StyleHelper.windowtextcolorrole
                    font.family: StylePrivate.StyleHelper.font.family
                    font.styleName: StylePrivate.StyleHelper.font.styleName
                    Layout.alignment: Qt.AlignCenter
                }
            }

            RowLayout {
                width: 272; height: Style.tabletScaleFactor * 46
                spacing: 20; Layout.leftMargin: 255
                Layout.rightMargin: Style.tabletScaleFactor * 40
                Layout.bottomMargin: Style.tabletScaleFactor * 15
                Button {
                    id: cancelBtn
                    width: 126; height: Style.tabletScaleFactor * 46
                    StylePrivate.StyleHelper.buttonType:"MinButton"
                    text: qsTr("Cancel")
                    onClicked: {
                        uninstallDialog.close()
                    }
                }
                Button {
                    id: confirmBtn
                    width: 126; height: Style.tabletScaleFactor * 46
                    StylePrivate.StyleHelper.buttonType:"blueButton"
                    text: qsTr("OK")
                    onClicked: {
                        uninstallDialog.close()
                        modelManager.uninsatllApp(desktopFile)
                    }
                }
            }
        }
    }
}
